#include<iostream>
using namespace std;
struct FlistNode
{
	int val;
	FlistNode *next;
	FlistNode(const int x) :val(x), next(0){}
};
//剑指offer题15：输入一个单链表，反转链表后，输出链表的所有元素。
void ReverseSinglyLinkList(FlistNode *head)
{
	FlistNode *prev = NULL, *cur = head, *next = NULL;
	if (cur)next = cur->next;
	while (cur)//逆置单链表
	{
		cur->next = prev;
		prev = cur;
		cur = next;
		if (next)next = next->next;
	}
	while (prev)
	{
		cout << prev->val << " ";
		prev = prev->next;
	}cout << endl;
}
int main()
{
	FlistNode* head1 = new FlistNode(1);
	FlistNode* head2 = new FlistNode(2); head1->next = head2;
	FlistNode* head3 = new FlistNode(3); head2->next = head3;
	FlistNode* head4 = new FlistNode(4); head3->next = head4;
	FlistNode* head5 = new FlistNode(5); head4->next = head5;
	FlistNode* head6 = new FlistNode(6); head5->next = head6;
	ReverseSinglyLinkList(head1);

	return 0;
}
